<html>
<head><title>Cypher Generator</title>
<link rel="stylesheet" type="text/css" href="../css/Default.css" />
<Script language="javascript" src="password.js"></script>
<Script language="javascript" src="../exec/login.js"></script>
<noscript>
location.href="noscript.html";
</noscript>
<SCRIPT LANGUAGE="JavaScript">

window.onload = redir(0);//we don't want just anyone using this page.

function start(){
	var usr=prompt("Enter the username","").toLowerCase();
	var pass=prompt("Enter the password","").toLowerCase();
	var oldKey =confirm("Would you like to use the key that is currently in use?");
	var k="";
	var keyA=new Array();
	if( oldKey ){
		keyA=key;
	}else{
		k=prompt("Enter the key. This should be a bunch of numbers seperated by commas.","Or leave this blank to generate a new key.");
		keyA = k.split(",");
		if(keyA.length <= 1){
			keyA = hexToByteArray( genkey() );
		}
	}

	k=buildArray(keyA);

	var genNew = confirm("Are you sure you would like to generate with the following information (things will be case insensitive); username: "
		+usr+", password: "+pass+", and the key: "+k+"?");

	if(!genNew){return;}

	var plaintext = usr+":"+pass;
	var ciphertext = byteArrayToHex( rijndaelEncrypt(plaintext,keyA, "ECB"));
	var decryptedtext = byteArrayToString(rijndaelDecrypt( hexToByteArray(ciphertext), keyA, "ECB"));
	alert("This is the code to paste into the password.js file:"+ciphertext);	
}

function buildArray(arr){
	var ret = "";
	for(var i=0; i<arr.length; i++){
		ret += arr[i]+",";
	}
	return ret;
}
</SCRIPT>
</HEAD>
<body onkeypress="keyPress(event)">
<center>
<img src= "../media/Gold_Lion.jpg"/>
<br>
<input type="button" onclick='start()' value="Start Generating">

<script>
//this is for using the 'enter' key to submit the data
	function keyPress(event){
		if(event.which == 13){
			start();
		}
	}
</script>
</center>
</body>
</html>
